//
//  XJLocationCell.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/29.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJLocationCell.h"
@interface XJLocationCell()
@property(nonatomic, strong) UIView *bgView;
@property(nonatomic, strong) UIImageView *iconIv;
@property(nonatomic, strong) UILabel *nameLabel;
@property(nonatomic, strong) UILabel *addressLabel;

@end
@implementation XJLocationCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
   self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView{
    [self.contentView addSubview:self.bgView];
    
    [self.bgView addSubview:self.iconIv];
    [self.bgView addSubview:self.nameLabel];
    [self.bgView addSubview:self.addressLabel];
}

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
    }
    return _bgView;
}

- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [[UIImageView alloc] init];
    }
    return _iconIv;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
    }
    return _nameLabel;
}
- (UILabel *)addressLabel {
    if (!_addressLabel) {
        _addressLabel = [UILabel new];
        _addressLabel.font = XJFONTSET_R(13.0);
        _addressLabel.numberOfLines = 0;
        _addressLabel.textColor = XJCOLOR_RGB(110, 110, 110);
    }
    return _addressLabel;
}


// 10 + (30+5+ x 5)+10;
- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat k5 = 5;
    CGFloat k10 = 10;
    
    // 高度自适应
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(k10);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(10, 13));
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIv.mas_right).offset(k5);
        make.top.equalTo(self.bgView.mas_top).offset(k10);
        make.right.equalTo(self.bgView.mas_right);
        make.height.mas_equalTo(30);
    }];
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_left);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(k5);
        make.bottom.mas_equalTo(self.bgView.mas_bottom).offset(-k5);
        make.right.equalTo(self.bgView.mas_right);
    }];
}


#pragma mark - 赋值
- (void)configureXJLocationCellWithIcon:(NSString *)icon name:(NSString *)name address:(NSString *)address {
    self.iconIv.image = [UIImage imageNamed:icon];
    
    self.nameLabel.text = name;
    self.addressLabel.text = address;
}















@end
